<div class="content-section introduction">
    <div class="feature-intro">
        <h1>Tree <span>Lazy</span></h1>
        <p>Lazy loading is handy when dealing with huge datasets. This example imitates a lazy loading case with timeouts.</p>
    </div>
    <app-demoActions github="tree" stackblitz="treelazy-demo"></app-demoActions>
</div>

<div class="content-section implementation">
    <div class="card">
        <p-tree [value]="files" (onNodeExpand)="nodeExpand($event)" [loading]="loading"></p-tree>
        
        <p-toast></p-toast>
    </div>
</div>

<div class="content-section documentation">
    <p-tabView>
        <p-tabPanel header="Source">
            <a href="https://github.com/primefaces/primeng/tree/master/src/app/showcase/components/tree" class="btn-viewsource" target="_blank">
                <span>View on GitHub</span>
            </a>
            <a href="https://stackblitz.com/edit/primeng-treelazy-demo" class="btn-viewsource" style="margin-left: .5em;" target="_blank">
                <span>Edit in StackBlitz</span>
            </a>
<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-tree [value]="files" (onNodeExpand)="nodeExpand($event)" [loading]="loading"&gt;&lt;/p-tree&gt;

&lt;p-toast&gt;&lt;/p-toast&gt;
</app-code>
<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
import &#123;Component,OnInit&#125; from '@angular/core';
import &#123;NodeService&#125; from '../../service/nodeservice';
import &#123;TreeNode&#125; from 'primeng/api';
import &#123;MessageService&#125; from 'primeng/api';

@Component(&#123;
    templateUrl: './treelazydemo.html',
    providers: [MessageService]
&#125;)
export class TreeLazyDemo implements OnInit &#123;

    files: TreeNode[];

    loading: boolean;
    
    constructor(private nodeService: NodeService, private messageService: MessageService) &#123; &#125;

    ngOnInit() &#123;
        this.loading = true;
        setTimeout(() => &#123;
            this.nodeService.getLazyFiles().then(files => this.files = files);
            this.loading = false;
        &#125;, 1000);
    &#125;

    nodeExpand(event) &#123;
        if (event.node) &#123;
            //in a real application, make a call to a remote url to load children of the current node and add the new nodes as children
            this.nodeService.getLazyFiles().then(nodes => &#123;
                event.node.children = nodes
                this.messageService.add(&#123;severity: 'info', summary: 'Children Loaded', detail: event.node.label&#125;);
            &#125;);
        &#125;
    &#125;
&#125;
</app-code>   
        </p-tabPanel>
        <p-tabPanel header="StackBlitz">
            <ng-template pTemplate="content">
                <iframe src="https://stackblitz.com/edit/primeng-treelazy-demo?embed=1" style="width: 100%; height: 768px; border: none;"></iframe>
            </ng-template>
        </p-tabPanel>
    </p-tabView>
</div>